package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.CartService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/user/shoppingCart")
public class CartController {

    @Autowired
    private CartService cartService;

    /**
     * 添加购物车
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        cartService.add(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 查看购物车
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查看我的购物车")
    public Result<List<ShoppingCart>> list(){
        List<ShoppingCart> cartList = cartService.list();
        return Result.success(cartList);
    }
    /**
     * 删除购物车
     * @return
     */
    @PostMapping("/sub")
    @ApiOperation("删除购物车")
    public  Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO){
        cartService.sub(shoppingCartDTO);
        return  Result.success();
    }
    /**
     * 清空购物车商品
     * @return
     */
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车商品")
    public Result<String> clean(){
        cartService.cleanShoppingCart();
        return Result.success();
    }
}
